cd $env(POLYN)

set flash epcs_flash_controller_0

source ./tcl/all_begin.tcl

set s [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {nios2-configure-sof} -C ./fw]
set p [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {nios2-flash-programmer-generate} \
        --sopcinfo [lindex [glob "./fw/*.sopcinfo"] 0] --flash-dir ./fw/tmp    \
        --instance 1 --program-flash --erase-first \
        --add-elf [lindex [glob "./fw/*.elf"] 0] $flash \
        --add-sof [lindex [glob "./fw/*.sof"] 0] $flash 0 \
       # --add-bin config.bin epcs_flash_controller_0 400000 \
]
set t [exec hg log -r . --verbose]
set file [open ./fw/tmp/config.bin w+]
puts $file $t
close $file
set b [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {bin2flash} --input=./fw/tmp/config.bin --output=./fw/tmp/config.flash  --location=0x600000]
set p [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {nios2-flash-programmer} \
        --epcs --base 9800 --instance 1 --erase 0x600000+2048 --program --go \
        ./fw/tmp/config.flash --silent \
]

set t [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" find ./fw/tmp/ -type f -delete]

set t [exec thg tag Programmed]
exit
